<%@ page import="java.util.List" %>

<%@ taglib uri="/WEB-INF/bpmapp.tld" prefix="ssp" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<% 
String ctPath = request.getContextPath();

String exitURL = "/loginPage.do";
String hostPage = "/cm/pageFlowContainer.do";
if( ctPath.equals("/bvmc") ) {
  exitURL = "/cm/closeWindowAlwaysRefresh.do";
  hostPage = "/cm/pageFlowContainer.do";
}

%>

<SCRIPT language="javascript">
 
function doAction(launchURL){
  var win = window.open(launchURL,"","toolbar=0,scrollbars=yes,location=0,statusbar=0,height=600,width=600,left=50,top=50,resizable=yes,menubar=0");

  if (win != null){
    if (win.opener == null)
      win.opener = self;
    win.focus();
  }
}
</SCRIPT>

<div class="blockSubtitle">
  <bean:message bundle="appCommonRes" key="bp.tasks.collaboration.title" />
</div>

<div class="blockWrap">
    <table width="100%" class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Task Inbox">

      <tr class="listHeader">
        <th id="Priority" align="center">
          <img src="<%= ctPath %>/ca/images/icons/priority_header.gif" border="0" alt="<bean:message key="cs.image.alt.priority"/>" title="<bean:message key="cs.image.alt.priority"/>" align="absmiddle">
        </th>
        <th id="Subject" align="left">
          <bean:message bundle="appCommonRes" key="bp.alerts.subject" />
        </th>
        <th id="DueDate" align="left">
          <bean:message bundle="appCommonRes" key="bp.dueDate" />
        </th>
      </tr>

<ssp:queryTask id="taskList" taskType="COLLABORATION_SPACE_TASKS" hostPage="<%=hostPage%>" exitURL="<%=exitURL%>" />

<logic:iterate id="taskItem" name="taskList" indexId="index">
        <logic:equal name="taskItem" property="isOverDue" value="false">
          <tr class="<%=index.intValue() % 2 == 0? "listEven" : "listOdd" %>" >
        </logic:equal>
        <logic:equal name="taskItem" property="isOverDue" value="true">
          <tr class="<%=index.intValue() % 2 == 0? "overDueEven" : "overDueOdd" %>" >
        </logic:equal>


        <td headers="Priority" align="center">
           <img src="<%= ctPath %>/ca/images/icons/<bean:message bundle="appCommonRes" name="taskItem" property ="priorityImage" />" alt="<bean:message key="cs.image.alt.priority"/>" title="<bean:message key="cs.image.alt.priority"/>">
        </td>

        <td headers="Subject">
        <% if(ctPath.equals("/bvmc") ) { %>
	    <a href="JavaScript:doAction('<bean:write name="taskItem" property="previewURL"/>')" >
        <% } else { %>
          <a href="<bean:write name="taskItem" property="previewURL"/>" >
        <% } %>
            <bean:write name="taskItem" property = "subject"  /> 
          </a>
        </td>

        <td headers="DueDate">
           <bean:write name="taskItem" property ="dueDate" formatKey="format.datetime.short"/>
        </td>

      </tr>
</logic:iterate>


<ssp:queryTask id="clTaskList" taskType="COLLABORATION_SPACE_CHECKLIST_TASKS" hostPage="<%=hostPage%>" exitURL="<%=exitURL%>" />

<logic:iterate id="clTaskItem" name="clTaskList" indexId="index">

        <logic:equal name="clTaskItem" property="isOverDue" value="false">
          <tr class="<%=index.intValue() % 2 == 0? "listEven" : "listOdd" %>" >
        </logic:equal>
        <logic:equal name="clTaskItem" property="isOverDue" value="true">
          <tr class="<%=index.intValue() % 2 == 0? "overDueEven" : "overDueOdd" %>" >
        </logic:equal>


        <td headers="Priority" align="center">
           <img src="<%= ctPath %>/ca/images/icons/<bean:message bundle="appCommonRes" name="clTaskItem" property ="priorityImage" />" alt="<bean:message key="cs.image.alt.priority"/>" title="<bean:message key="cs.image.alt.priority"/>">
        </td>

        <td headers="Subject">
        <% if(ctPath.equals("/bvmc") ) { %>
	    <a href="JavaScript:doAction('<bean:write name="clTaskItem" property="previewURL"/>')" >
        <% } else { %>
          <a href="<bean:write name="clTaskItem" property="previewURL"/>" >
        <% } %>
            <bean:write name="clTaskItem" property = "subject"  /> 
          </a>
        </td>

        <td headers="DueDate">
           <bean:write name="clTaskItem" property ="dueDate" formatKey="format.datetime.short"/>
        </td>

      </tr>
</logic:iterate>


      <%
         int numTasks = ((List)pageContext.getAttribute("taskList")).size() + ((List)pageContext.getAttribute("clTaskList")).size();

         if (numTasks <= 0)
         {
      %>

      <tr class="listOdd">
        <td colspan="4" align="center">
        <bean:message bundle="appCommonRes" key="bp.tasks.noCollaborationTasks" />
        </td>
      </tr>

      <%
         }
      %>



    </table>
</div>
